package com.hawthorn.admin.controller.sysdealer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hawthorn.admin.service.sysdealer.SysDealerService;
import com.hawthorn.platform.annotation.MarkLog;
import com.hawthorn.platform.exception.BizCode;
import com.hawthorn.platform.utils.common.MyUtil;
import com.hawthorn.platform.utils.iassert.AssertMyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.Map;

/**
 * <p>todo 渠道商档案表 controller</p>
 * @author: zhouxin@expservice.com.cn
 * @created: 2022-07-08 3:38 PM
 * @lasted: 2022-07-21 9:40 AM
 * @version v1.0.2
 */
@Api(tags = {"admin-dealer"})
@RestController
@RequestMapping("/dealer/")
public class SysDealerController
{

  @Resource
  public SysDealerService sysDealerService;

  /**
   * <p>todo 查询渠道商档案表信息 </p>
   * @author: zhouxin@expservice.com.cn
   * @date: 2022-07-08 3:38 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "查询->渠道商档案表信息", notes = "查询渠道商档案表信息服务")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "查询条件参数", dataTypeClass = String.class)
  })
  @PostMapping(value = "/find")
  public IPage<Map<String, Object>> find(@RequestBody String params) throws ParseException
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return sysDealerService.find(page, conditions);
  }

  /**
   * <p>todo 保存渠道商档案表</p>
   * @author: zhouxin@expservice.com.cn
   * @date: 2022-07-08 3:38 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "保存->渠道商档案表", notes = "保存渠道商档案表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "保存参数", dataTypeClass = Map.class)
  })
  @PostMapping(value = "/save")
  @MarkLog(value = "新增渠道商", param = "id")
  public Map<String, Object> save(@RequestBody Map<String, Object> param)
  {
    return sysDealerService.save(param);
  }

  /**
   * <p>todo 更新渠道商档案表</p>
   * @author: zhouxin@expservice.com.cn
   * @date: 2022-07-08 3:38 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "更新->渠道商档案表", notes = "更新渠道商档案表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
      @ApiImplicitParam(name = "param", value = "更新参数", dataTypeClass = Map.class)
  })
  @PutMapping(value = "/update/{id}")
  @MarkLog(value = "修改渠道商", param = "id")
  public Map<String, Object> update(@PathVariable("id") Long id, @RequestBody Map<String, Object> param)
  {
    return sysDealerService.update(id, param);
  }

  /**
   * <p>todo 导出渠道商档案表</p>
   * @author: zhouxin@expservice.com.cn
   * @date: 2022-07-08 3:38 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "导出->渠道商档案表", notes = "导出渠道商档案表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "response", value = "response", dataTypeClass = HttpServletResponse.class),
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/export")
  public void export(HttpServletResponse response, @RequestBody Map<String, Object> param) throws IOException
  {
    AssertMyUtil.notNull(param, BizCode.VARIABLE_NOT_EMPTY, "param");
    sysDealerService.export(response, "门店数据", param);
  }

  /**
   * <p>todo 修改渠道商档案表状态</p >
   * @author: zhouxin@expservice.com.cn
   * @date: 2022-07-14 3:41 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "修改->状态", notes = "修改状态")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
      @ApiImplicitParam(name = "params", value = "null", dataTypeClass = String.class)
  })
  @PostMapping(value = "/changeStatus/{id}")
  @MarkLog(value = "修改渠道商状态", param = "id")
  public Integer changeStatus(@PathVariable("id") Long id, @RequestBody String status)
  {
    return sysDealerService.changeStatus(id, status);
  }
}
